﻿DELIMITER //

--
--
DROP PROCEDURE IF EXISTS spZeusPackageStore
//

-- HU - Rakomány tárolása
-- EN - Package Storing
--
--
CREATE PROCEDURE spZeusPackageStore 
  (_AccessToken INTEGER, _Code VARCHAR(20), _LocationCode VARCHAR(20))
BEGIN
  DECLARE _Rows INTEGER;
  DECLARE _UserID INTEGER;
  DECLARE _Lang VARCHAR(10);

  --
  --
  CALL spAccessTokenCheck(_AccessToken, _UserID, _Lang);
  

  -- HU - Tárhelyre kerül
  -- EN - Set loaction
  --
  BEGIN
    DECLARE EXIT HANDLER FOR SQLEXCEPTION SET _Rows = 0;

    UPDATE ZeusPackage
       SET LocationCode = _LocationCode
     WHERE Code = _Code;

    -- SET PDO::MYSQL_ATTR_FOUND_ROWS => true
    --
    SET _Rows = ROW_COUNT();

  END;

  IF (_Rows != 1) THEN

    IF (_Lang = 'HU') THEN
      SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = N'Nincs ilyen rakomány !';
    END IF;

    IF (_Lang = 'EN') THEN
      SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = N'Package not found !';
    END IF;

    IF (_Lang = 'DE') THEN
      SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = N'Keine solche Fracht !';
    END IF;    
  END IF;


  -- HU - Visszaadja ennek a Rakománynak az adatait
  -- EN - Get the package details
  --
  SELECT Code, ArticleCode, ArticleName, 
         
         CAST(REPLACE(Expired, '.', '') as DATE) Expired, 
    
         LocationCode, Quantity, UnitCode, '' Notes

    FROM ZeusPackage
   WHERE Code = _Code;

END
//
